package s7.hopeluancher.nbhope.com.s7;

import android.util.Log;

import com.orvibo.homemate.api.LocalDataApi;
import com.orvibo.homemate.api.UserApi;
import com.orvibo.homemate.api.listener.BaseResultListener;
import com.orvibo.homemate.application.ViHomeApplication;
import com.orvibo.homemate.bo.Device;
import com.orvibo.homemate.event.BaseEvent;
import com.orvibo.homemate.model.family.FamilyManage;
import com.orvibo.homemate.util.MyLogger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wang4 on 2017/6/1.
 */

public class TestApp extends ViHomeApplication {
    public final String userName = "13777115653";
    public final String password = "hope2016";

    private static List<Device> mAllDevice = new ArrayList<>();

    @Override
    public void onCreate() {
        super.onCreate();
        initOrviboSDK();
    }

    private void initOrviboSDK() {

        ViHomeApplication.context = getApplicationContext();
        //TODO 需要替换为真实的source
        UserApi.init("HopeLuancher", 0);


        //获取userName上一次使用的familyId，如果没有登录过则为null。
        // 这里是保证当前登录账号的家庭为上一次的家庭，避免同一个账号退出重新登录后又回到默认家庭
        String familyId = FamilyManage.getFamilyId(userName);
        UserApi.login(userName, password, familyId, new BaseResultListener() {
            @Override
            public void onResultReturn(BaseEvent baseEvent) {
                MyLogger.jLog().e(baseEvent);
                Log.e("login", baseEvent + "");
                if (baseEvent.getResult() == 0) {
                    getDevices();//主机下设备
                }
            }
        });
    }

    private void getDevices() {
        String familyId = FamilyManage.getCurrentFamilyId();
        mAllDevice = LocalDataApi.getDevicesByFamily(familyId);
        List<Device> devices1 = LocalDataApi.getDevicesByRoom(familyId, "8a4d4da031a34b958800daee3ca35d7f");
        Log.d("wangjianping", "获取到设备：" + mAllDevice + "房间下列表" + devices1);
    }
}
